#include "StdAfx.h"
#include "AgentEventHandler.h"


CAgentEventHandler::CAgentEventHandler()
{
	m_SetLoadCompleted = 0;
	m_LoadCompletedCriticalSection.InitializeCriticalSection();
	m_DatabaseCriticalSection.InitializeCriticalSection();
}


CAgentEventHandler::~CAgentEventHandler()
{
	m_DatabaseCriticalSection.DeleteCriticalSection();
}

void CAgentEventHandler::AddBrowserContext(BrowserAgent *_pBrowserAgent)
{
	if (NULL == GetAgentEventHandler().m_BrowserAgentList[(BrowserAgent *)_pBrowserAgent])
	{
		GetAgentEventHandler().m_BrowserAgentList[(BrowserAgent *)_pBrowserAgent] = true;
	}
		
};

CAgentEventHandler& CAgentEventHandler::GetAgentEventHandler()
{
	static CAgentEventHandler s_PhoneAgentEventHandler;
	CAgentEventHandler * sfda = &s_PhoneAgentEventHandler;
	return s_PhoneAgentEventHandler;
}


void CAgentEventHandler::SetLoadCompleted()
{
	GetAgentEventHandler().m_LoadCompletedCriticalSection.EnterCriticalSection();
	if (GetAgentEventHandler().m_SetLoadCompleted == 0)
	{
		GetAgentEventHandler().m_SetLoadCompleted = 1;
		GetAgentEventHandler().m_LoadCompletedCriticalSection.LeaveCriticalSection();
		DataCacheEventHandler(NULL);
		return ;
	}
	GetAgentEventHandler().m_LoadCompletedCriticalSection.LeaveCriticalSection();
};

unsigned __stdcall CAgentEventHandler::AppUninstallThread(void* context00)
{

	BrowserContext* context = (BrowserContext*)context00;

	context->WebAppCallbackExternal(L"data", L"Fdsa");
	context->WebAppCallbackExternal(L"data2", L"fdafda");
	context->WebAppCallbackEvent(L"_AppUninstall", L"ok");

	return 0;	
};


void CAgentEventHandler::SendToBrowserContext(PEVENT_CALLBACK s_pEcb,bool (*fun)(PEVENT_CALLBACK,wstring&,bool&,wstring&,wstring&))
{
	bool isruned= false;
	std::map<BrowserAgent*,bool>::iterator it= GetAgentEventHandler().m_BrowserAgentList.begin();
	for (;it!=GetAgentEventHandler().m_BrowserAgentList.end();)
	{
		BrowserContext* context = (*it).first->CreateBrowserContext();
		if (context != NULL )
		{
			GetAgentEventHandler().m_DatabaseCriticalSection.EnterCriticalSection();
			if (GetAgentEventHandler().m_wstrDatabase.empty())
			{
				context->WebAppDatabase(GetAgentEventHandler().m_wstrDatabase);
				wstring sda= GetAgentEventHandler().m_wstrDatabase;
				int fdsa=0;
			}
			GetAgentEventHandler().m_DatabaseCriticalSection.LeaveCriticalSection();
			wstring funname;
			wstring data1;
			wstring data2;

			bool isbreak = fun(s_pEcb,funname,isruned,data1,data2) ;
			
			//if (funname == L"_AppUninstall")
			//{
			//	unsigned int threadId = 0;
			//	HANDLE hThread = (HANDLE)_beginthreadex(NULL,0,CAgentEventHandler::AppUninstallThread,(BrowserContext*)context,0,&threadId); 
			//	if (NULL != hThread)
			//	{
			//		CloseHandle(hThread);
			//	}

			//}else
			//{
			
				context->WebAppCallbackExternal(L"data", data1.c_str());
				context->WebAppCallbackExternal(L"data2", data2.c_str());
				context->WebAppCallbackEvent(funname.c_str(), L"ok");
				
				(*it).first->ReleaseBrowserContext(context);
			//}

			if (isbreak	==true )
			{
				break;
			}
		}
		it++;
	}
}



int CAgentEventHandler::AcceptAppEvent(AppEvent_StatusType eAst,AppEvent_ErrorCode eAec,PEVENT_CALLBACK s_pEcb)
{
	if ( NULL == s_pEcb )
	{
		return 0;
	}

	switch(eAst)
	{
	case APPEVENT_PHONECALLBACK_GET_APPLIST:
		SendToBrowserContext(s_pEcb,GetAppListEventHandler);//GetAppListEventHandler(s_pEcb);
		break;
	case APPEVENT_PHONECALLBACK_GET_APPCOUNT:
		SendToBrowserContext(s_pEcb,GetAppCountEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_APP_INSTALL:
		SendToBrowserContext(s_pEcb,AppInstallEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_APP_UNINSTALL:
		SendToBrowserContext(s_pEcb,AppUninstallEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_APP_REINSTALL:
		SendToBrowserContext(s_pEcb,AppReinstallEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_GET_FILELIST:
		SendToBrowserContext(s_pEcb,GetFileListEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_GET_MEDIAFILELIST:
		SendToBrowserContext(s_pEcb,GetMediaFileListEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_GET_MEDIAFILECOUNT:
		SendToBrowserContext(s_pEcb,GetMediaFileCountEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_FILE_COPYTOPHONE:
		SendToBrowserContext(s_pEcb,FileCopyToPhoneEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_FILE_COPYTOPC:
		SendToBrowserContext(s_pEcb,FileCopyToPCEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_FILE_MOVETOPHONE:
		SendToBrowserContext(s_pEcb,FileMoveToPhoneEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_FILE_MOVETOPC:
		SendToBrowserContext(s_pEcb,FileMoveToPCEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_FILE_MULTICOPYTOPHONE:
		SendToBrowserContext(s_pEcb,MultiFileCopyToPhoneEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_FILE_MULTICOPYTOPC:
		SendToBrowserContext(s_pEcb,MultiFileCopyToPCEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_FILE_RENAME:
		SendToBrowserContext(s_pEcb,FileRenameEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_DEL_FILE:
		SendToBrowserContext(s_pEcb,DelFileEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_CREATEDIRECTORY:
		SendToBrowserContext(s_pEcb,CreateDirectoryEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_FOLDER_RENAME:
		SendToBrowserContext(s_pEcb,FolderRenameEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_DEL_FOLDER:
		SendToBrowserContext(s_pEcb,DelFolderEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_GET_CONTACTLIST:
		SendToBrowserContext(s_pEcb,GetContactListEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_GET_CONTACTCOUNT:
		SendToBrowserContext(s_pEcb,GetContactCountEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_ADD_CONTACT:
		SendToBrowserContext(s_pEcb,AddContactEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_DEL_CONTACT:
		SendToBrowserContext(s_pEcb,DelContactEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_SET_CONTACT:
		SendToBrowserContext(s_pEcb,SetContactEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_GET_SMSLIST:
		SendToBrowserContext(s_pEcb,GetSMSListEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_GET_SMSCOUNT:
		SendToBrowserContext(s_pEcb,GetSMSCountEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_ADD_SMS:
		SendToBrowserContext(s_pEcb,AddSMSEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_BACK_SMS:
		SendToBrowserContext(s_pEcb,BackSMSEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_DEL_SMS:
		SendToBrowserContext(s_pEcb,DelSMSEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_SET_SMS:
		SendToBrowserContext(s_pEcb,SetSMSEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_SERVICE_INSTALL:
		SendToBrowserContext(s_pEcb,ServiceInstallEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_GET_PHONEINFO:
		SendToBrowserContext(s_pEcb,GetPhoneInfoEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_MOVEAPP2SD:
		SendToBrowserContext(s_pEcb,MoveApp2SDEventHandler);
		break;
	case APPEVENT_PHONECALLBACK_MOVEAPP2MEM:
		SendToBrowserContext(s_pEcb,MoveApp2MemEventHandler);
		break;
	case APPEVENT_DATACACHE_DATACACHE_CHANGED:
		DataCacheEventHandler(s_pEcb);
		break;
	}
	return 0;
};


bool CAgentEventHandler::AppInstallEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", str::itowstring(s_pEcb->bParameter).c_str());
	//context->WebAppCallbackExternal(L"data2",str::itowstring(s_pEcb->nFileType).c_str());
	//context->WebAppCallbackEvent(L"_AppInstall", L"ok");
	return false;
}

bool CAgentEventHandler::FileCopyToPhoneEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}

bool CAgentEventHandler::FileCopyToPCEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{	
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}

bool CAgentEventHandler::MultiFileCopyToPhoneEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}

bool CAgentEventHandler::MultiFileCopyToPCEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{

	data1=str::itowstring(s_pEcb->nParameter);
	funname=L"_MultiFileCopyToPC";
	return false;

}

bool CAgentEventHandler::GetAppListEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	if (isruned == false)
	{
		if ( CSqliteOpt::GetSqliteOptInst().SetDbFile(str::UnicodeToAnsi(GetAgentEventHandler().m_wstrDatabase))== SQLITE_OK)
		{
			string imei = str::UnicodeToAnsi(s_pEcb->wstrPhoneIMEI);
			string json = str::UnicodeToAnsi(s_pEcb->wstrParameter);

			CSqliteOpt::GetSqliteOptInst().AddApp(imei,json);
			isruned = true;
		}
		CSqliteOpt::GetSqliteOptInst().CloseDbFile();
		
	}

	funname=L"_GetAppList";

	return false;
}

bool CAgentEventHandler::GetAppCountEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	data1=str::itowstring(s_pEcb->nParameter);
	funname=L"_GetAppCount";
	return false;
}


bool CAgentEventHandler::ServiceInstallEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}



bool CAgentEventHandler::GetContactListEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{

	if (isruned == false)
	{
		if ( CSqliteOpt::GetSqliteOptInst().SetDbFile(str::UnicodeToAnsi(GetAgentEventHandler().m_wstrDatabase))== SQLITE_OK)
		{
			string imei = str::UnicodeToAnsi(s_pEcb-> wstrPhoneIMEI);
			string json = str::UnicodeToAnsi(s_pEcb->wstrParameter);

			CSqliteOpt::GetSqliteOptInst().AddContact(imei,json);
		}
		CSqliteOpt::GetSqliteOptInst().CloseDbFile();
		isruned = true;
	}

	funname=L"_GetContactList";

	return false;
}


bool CAgentEventHandler::GetContactCountEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	data1=str::itowstring(s_pEcb->nParameter);
	funname=L"_GetContactCount";
	return false;
}


bool CAgentEventHandler::AddContactEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	data1=str::itowstring(s_pEcb->nParameter);
	funname=L"_AddContact";
	return false;
}


bool CAgentEventHandler::GetSMSListEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	if (isruned == false)
	{
		if ( CSqliteOpt::GetSqliteOptInst().SetDbFile(str::UnicodeToAnsi(GetAgentEventHandler().m_wstrDatabase))== SQLITE_OK)
		{
			string imei = str::UnicodeToAnsi(s_pEcb->wstrPhoneIMEI);
			string json = str::UnicodeToAnsi(s_pEcb->wstrParameter);

			CSqliteOpt::GetSqliteOptInst().AddSMS(imei,json);
		}
		CSqliteOpt::GetSqliteOptInst().CloseDbFile();
		isruned = true;
	}

	funname=L"_GetSMSList";

	return false;
}


bool CAgentEventHandler::GetSMSCountEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	data1=str::itowstring(s_pEcb->nParameter);
	funname=L"_GetSMSCount";
	return false;
}

bool CAgentEventHandler::AddSMSEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	data1=str::itowstring(s_pEcb->nParameter);
	funname=L"_AddSMS";
	return false;
}



bool CAgentEventHandler::SetSMSEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	data1=str::itowstring(s_pEcb->nParameter);
	funname=L"_SetSMS";
	return false;
}



bool CAgentEventHandler::GetMediaFileListEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	if (isruned == false)
	{
		if ( CSqliteOpt::GetSqliteOptInst().SetDbFile(str::UnicodeToAnsi(GetAgentEventHandler().m_wstrDatabase))== SQLITE_OK)
		{
			string imei = str::UnicodeToAnsi(s_pEcb->wstrPhoneIMEI);
			string json = str::UnicodeToAnsi(s_pEcb->wstrParameter);

			CSqliteOpt::GetSqliteOptInst().AddFile(imei,json);
		}
		CSqliteOpt::GetSqliteOptInst().CloseDbFile();
		isruned = true;
	}

	funname=L"_GetMediaFileList";

	return false;
}


bool CAgentEventHandler::GetMediaFileCountEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	PGET_MEDIAFILE_CNT_RES res = (PGET_MEDIAFILE_CNT_RES)s_pEcb->pParameter;
	data1=str::itowstring(res->nRes);
	data2=str::itowstring(res->nFileType);
	funname=L"_GetMediaFileCount";
	return false;
}


bool CAgentEventHandler::GetFileListEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//data1=str::itowstring(s_pEcb->nParameter);
	//funname=L"_";
	return false;
}


bool CAgentEventHandler::AppUninstallEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{

	if (isruned == false)
	{
		if (s_pEcb->nParameter == 1 )
		{
			if ( CSqliteOpt::GetSqliteOptInst().SetDbFile(str::UnicodeToAnsi(GetAgentEventHandler().m_wstrDatabase))== SQLITE_OK)
			{
				EVENT_CALLBACK s_Ecb = CAgentEventHandler::GetAgentEventHandler().m_EcbList[PARAMETER_CACHE_APPUNINSTALL];

				CSqliteOpt::GetSqliteOptInst().DelApp(str::UnicodeToAnsi(s_Ecb.wstrPhoneIMEI),str::UnicodeToAnsi(s_Ecb.wstrParameter2));
			}
			//CSqliteOpt::GetSqliteOptInst().CloseDbFile();
		}
		isruned = true;
	}
	data1=str::itowstring(s_pEcb->nParameter);


	funname=L"_AppUninstall";

	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}



bool CAgentEventHandler::AppReinstallEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}



bool CAgentEventHandler::BackSMSEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}


bool CAgentEventHandler::CreateDirectoryEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}



bool CAgentEventHandler::DelFolderEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}



bool CAgentEventHandler::DelFileEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	if (isruned == false)
	{
		if (s_pEcb->nParameter == 1 )
		{
			if ( CSqliteOpt::GetSqliteOptInst().SetDbFile(str::UnicodeToAnsi(GetAgentEventHandler().m_wstrDatabase))== SQLITE_OK)
			{
				EVENT_CALLBACK s_Ecb = CAgentEventHandler::GetAgentEventHandler().m_EcbList[PARAMETER_CACHE_DELFILE];

				CSqliteOpt::GetSqliteOptInst().DelFile(str::UnicodeToAnsi(s_Ecb.wstrPhoneIMEI),str::UnicodeToAnsi(s_Ecb.wstrParameter),str::UnicodeToAnsi(s_Ecb.wstrParameter2));
			}
			CSqliteOpt::GetSqliteOptInst().CloseDbFile();
		}
		isruned = true;
	}
	data1=str::itowstring(s_pEcb->nParameter);
	funname=L"_DelFile";
	return false;
}



bool CAgentEventHandler::DelSMSEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
		if (isruned == false)
		{
			if (s_pEcb->nParameter == 1 )
			{
				if ( CSqliteOpt::GetSqliteOptInst().SetDbFile(str::UnicodeToAnsi(GetAgentEventHandler().m_wstrDatabase))== SQLITE_OK)
				{
					EVENT_CALLBACK s_Ecb = CAgentEventHandler::GetAgentEventHandler().m_EcbList[PARAMETER_CACHE_DELSMS];

					CSqliteOpt::GetSqliteOptInst().DelSMS(str::UnicodeToAnsi(s_Ecb.wstrPhoneIMEI),s_Ecb.nParameter2,s_Ecb.nParameter3);
				}
				CSqliteOpt::GetSqliteOptInst().CloseDbFile();
			}
			isruned = true;
		}
		data1=str::itowstring(s_pEcb->nParameter);
		funname=L"_DelSMS";
		return false;
}



bool CAgentEventHandler::DelContactEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	if (isruned == false)
	{
		if (s_pEcb->nParameter == 1 )
		{
			if ( CSqliteOpt::GetSqliteOptInst().SetDbFile(str::UnicodeToAnsi(GetAgentEventHandler().m_wstrDatabase))== SQLITE_OK)
			{
				EVENT_CALLBACK s_Ecb = CAgentEventHandler::GetAgentEventHandler().m_EcbList[PARAMETER_CACHE_DELCONTACT];

				CSqliteOpt::GetSqliteOptInst().DelContact(str::UnicodeToAnsi(s_Ecb.wstrPhoneIMEI),s_Ecb.nParameter2,s_Ecb.nParameter3);
			}
			CSqliteOpt::GetSqliteOptInst().CloseDbFile();

		}

		isruned = true;
	}
	data1=str::itowstring(s_pEcb->nParameter);
	funname=L"_DelContact";
	return false;
}



bool CAgentEventHandler::FileMoveToPCEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}



bool CAgentEventHandler::FileMoveToPhoneEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}



bool CAgentEventHandler::FileRenameEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}


bool CAgentEventHandler::FolderRenameEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}


bool CAgentEventHandler::GetPhoneInfoEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}


bool CAgentEventHandler::SetContactEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	//context->WebAppCallbackExternal(L"data", s_pEcb->);
	//context->WebAppCallbackExternal(L"data2", s_pEcb->);
	//context->WebAppCallbackEvent(L"_", L"ok");
	return false;
}


bool CAgentEventHandler::MoveApp2SDEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	data1=str::itowstring(s_pEcb->nParameter);
	funname=L"_MoveApp2SD";
	return false;
}


bool CAgentEventHandler::MoveApp2MemEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2)
{
	data1=str::itowstring(s_pEcb->nParameter);
	funname=L"_MoveApp2Mem";
	return false;
}



bool CAgentEventHandler::DataCacheEventHandler(PEVENT_CALLBACK s_pEcb)
{

	GetAgentEventHandler().m_LoadCompletedCriticalSection.EnterCriticalSection();
	if (GetAgentEventHandler().m_SetLoadCompleted == 0)
	{
		GetAgentEventHandler().m_LocalStorageStringCache.push_back(make_pair(s_pEcb->bstrParameter,s_pEcb->bstrParameter2));
		GetAgentEventHandler().m_LoadCompletedCriticalSection.LeaveCriticalSection();
		return true;
	}

	if (GetAgentEventHandler().m_SetLoadCompleted == 1)
	{
		while (!GetAgentEventHandler().m_LocalStorageStringCache.empty())
		{
			EVENT_CALLBACK s_Ecb;
			s_Ecb.bstrParameter  = (BSTR)GetAgentEventHandler().m_LocalStorageStringCache.front().first.c_str();
			s_Ecb.bstrParameter2 = (BSTR)GetAgentEventHandler().m_LocalStorageStringCache.front().second.c_str();
			DataCacheEventHandlerSub(&s_Ecb);
			GetAgentEventHandler().m_LocalStorageStringCache.pop_front();
		}
		GetAgentEventHandler().m_SetLoadCompleted = 2;
	}

	GetAgentEventHandler().m_LoadCompletedCriticalSection.LeaveCriticalSection();
	
	DataCacheEventHandlerSub(s_pEcb);

	return false;
}



bool CAgentEventHandler::DataCacheEventHandlerSub(PEVENT_CALLBACK s_pEcb)
{
	if (s_pEcb!=NULL)
	{
		std::map<BrowserAgent*,bool>::iterator it= GetAgentEventHandler().m_BrowserAgentList.begin();
		for (;it!=GetAgentEventHandler().m_BrowserAgentList.end();)
		{
			BrowserContext* context = (*it).first->CreateBrowserContext();
			if (context != NULL )
			{
				context->WebAppLocalStorageString(s_pEcb->bstrParameter ,s_pEcb->bstrParameter2);
				(*it).first->ReleaseBrowserContext(context);
			}
			it++;
		}
	}
	return false;
}
	


void CAgentEventHandler::AppInstall(const wstring &PhoneIndex,LONG nAppType,BSTR sSourceFile)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.nParameter2 = nAppType;
	s_pEcb.bstrParameter = sSourceFile ;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_APP_INSTALL,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::FileCopyToPhone(const wstring &PhoneIndex)
{
	//EVENT_CALLBACK s_pEcb;
	//s_pEcb.nParameter = PhoneIndex ;
	//s_pEcb.
	//s_pEcb.
	//GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::FileCopyToPC(const wstring &PhoneIndex)
{
	//EVENT_CALLBACK s_pEcb;
	//s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	//s_pEcb.
	//	s_pEcb.
	//GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::MultiFileCopyToPhone(const wstring &PhoneIndex,BSTR sSourceFileList,BSTR sTargetFolder)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.bstrParameter = sSourceFileList;
	s_pEcb.bstrParameter = sTargetFolder;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_FILE_MULTICOPYTOPHONE ,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::MultiFileCopyToPC(const wstring &PhoneIndex,BSTR sSourceFileList,BSTR sTargetFolder)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.bstrParameter = sSourceFileList;
	s_pEcb.bstrParameter2 = sTargetFolder;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_FILE_MULTICOPYTOPC,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::FileMoveToPC(const wstring &PhoneIndex)
{
	//EVENT_CALLBACK s_pEcb;
	//s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	//s_pEcb.
	//	s_pEcb.
	//GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::FileMoveToPhone(const wstring &PhoneIndex)
{
	//EVENT_CALLBACK s_pEcb;
	//s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	//s_pEcb.
	//	s_pEcb.
	//GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::GetAppList(const wstring &PhoneIndex)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_GET_APPLIST,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::GetAppCount(const wstring &PhoneIndex)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_GET_APPCOUNT,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::ServiceInstall(const wstring &PhoneIndex)
{
	//EVENT_CALLBACK s_pEcb;
	//s_pEcb.nParameter = PhoneIndex ;
	//s_pEcb.
	//	s_pEcb.
	//GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::GetContactList(const wstring &PhoneIndex)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_GET_CONTACTLIST,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::GetContactCount(const wstring &PhoneIndex)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_GET_CONTACTCOUNT,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::AddContact(const wstring &PhoneIndex,BSTR sContectInfo)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.bstrParameter = sContectInfo;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_ADD_CONTACT,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::GetSMSList(const wstring &PhoneIndex)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_GET_SMSLIST,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::GetSMSCount(const wstring &PhoneIndex)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_GET_SMSCOUNT,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::AddSMS(const wstring &PhoneIndex,BSTR sSmsInfo)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.bstrParameter = sSmsInfo ;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_ADD_SMS,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::SetSMS(const wstring &PhoneIndex,BSTR sSmsInfo)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.bstrParameter = sSmsInfo;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_SET_SMS,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::GetFileList(const wstring &PhoneIndex,BSTR strFolder)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.bstrParameter = strFolder;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_GET_FILELIST,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::GetMediaFileList(const wstring &PhoneIndex,LONG nType,BSTR sPath )
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.nParameter2 = nType;
	s_pEcb.bstrParameter = sPath;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_GET_MEDIAFILELIST,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::GetMediaFileCount(const wstring &PhoneIndex,LONG nType,BSTR sPath)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.nParameter2 = nType;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_GET_MEDIAFILECOUNT,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::AppUninstall(const wstring &PhoneIndex,BSTR pszAppName,BSTR pszAppUID)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.bstrParameter = pszAppName;
	s_pEcb.bstrParameter2 = pszAppUID;

	s_pEcb.wstrParameter = pszAppName;
	s_pEcb.wstrParameter2 = pszAppUID;
	CAgentEventHandler::GetAgentEventHandler().m_EcbList[PARAMETER_CACHE_APPUNINSTALL] = s_pEcb;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_APP_UNINSTALL,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::AppReinstall(const wstring &PhoneIndex,LONG nAppType,BSTR sSourceFile)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.nParameter2 = nAppType;
	s_pEcb.bstrParameter = sSourceFile;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_APP_REINSTALL,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::BackSMS(const wstring &PhoneIndex,BSTR sSmsInfo)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.bstrParameter = sSmsInfo;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_BACK_SMS,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::CreateDirectory(const wstring &PhoneIndex)
{
	//EVENT_CALLBACK s_pEcb;
	//s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	//s_pEcb.
	//	s_pEcb.
	//GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::DelFolder(const wstring &PhoneIndex)
{
	//EVENT_CALLBACK s_pEcb;
	//s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	//s_pEcb.
	//	s_pEcb.
	//GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::DelFile(const wstring &PhoneIndex, BSTR sFile, BSTR sPath, BSTR sName)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.bstrParameter = sFile;

	s_pEcb.wstrParameter = sPath;
	s_pEcb.wstrParameter2 = sName;

	CAgentEventHandler::GetAgentEventHandler().m_EcbList[PARAMETER_CACHE_DELFILE] = s_pEcb;

	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_DEL_FILE,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::DelSMS(const wstring &PhoneIndex,LONG nFolder,LONG nSMSIndex)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.nParameter2 = nFolder;
	s_pEcb.nParameter3 = nSMSIndex;

	CAgentEventHandler::GetAgentEventHandler().m_EcbList[PARAMETER_CACHE_DELSMS] = s_pEcb;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_DEL_SMS,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::DelContact(const wstring &PhoneIndex, LONG nFolder,LONG nContactIndex)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.nParameter2 = nFolder;
	s_pEcb.nParameter3 = nContactIndex;

	CAgentEventHandler::GetAgentEventHandler().m_EcbList[PARAMETER_CACHE_DELCONTACT] = s_pEcb;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_DEL_CONTACT,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::FileRename(const wstring &PhoneIndex)
{
	//EVENT_CALLBACK s_pEcb;
	//s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	//s_pEcb.
	//	s_pEcb.
	//GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::FolderRename(const wstring &PhoneIndex)
{
//	EVENT_CALLBACK s_pEcb;
//	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
//	s_pEcb.
//	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::GetPhoneInfo(const wstring &PhoneIndex)
{
	//EVENT_CALLBACK s_pEcb;
	//s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	//s_pEcb.
	//	s_pEcb.
	//GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::SetContact(const wstring &PhoneIndex, LONG nContactIndex,BSTR sContectInfo)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.nParameter2 = nContactIndex;
	s_pEcb.bstrParameter = sContectInfo;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_SET_CONTACT,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::MoveApp2SD(const wstring &PhoneIndex, BSTR pszAppId)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.bstrParameter = pszAppId;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_MOVEAPP2SD,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};
void CAgentEventHandler::MoveApp2Mem(const wstring &PhoneIndex, BSTR pszAppId)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.bstrParameter = pszAppId;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_DO_MOVEAPP2MEM,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};



void CAgentEventHandler::InitDownload(const wstring &PhoneIndex, BSTR strDownloadInfo)
{
	EVENT_CALLBACK s_pEcb;
	s_pEcb.wstrPhoneIMEI = PhoneIndex ;
	s_pEcb.bstrParameter = strDownloadInfo;
	GetAgentEventHandler().SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_INITDOWNLOAD,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};

void CAgentEventHandler::SetShoppingCartInfo(const wstring &PhoneIndex, BSTR strCartInfo)
{
	EVENT_CALLBACK s_Ecb;
	s_Ecb.wstrPhoneIMEI = PhoneIndex ;
	s_Ecb.bstrParameter = (BSTR)L"setshoppingcartinfo";
	s_Ecb.bstrParameter2 = (BSTR)strCartInfo;
	GetAgentEventHandler().SendAppEvent(APPEVENT_DATACACHE_SET_DATACACHE, APPEVENT_ERRORCODE_OK, &s_Ecb);
	
	//APPEVENT_DATACACHE_SET_DATACACHE
	//SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_SETSHOPPINGCARTINFO,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};

void CAgentEventHandler::SetDataCache(const wstring &PhoneIndex, BSTR pszKey,BSTR pszData)
{
	EVENT_CALLBACK s_Ecb;
	s_Ecb.bstrParameter = pszKey;
	s_Ecb.bstrParameter2 = pszData;
	GetAgentEventHandler().SendAppEvent(APPEVENT_DATACACHE_SET_DATACACHE, APPEVENT_ERRORCODE_OK, &s_Ecb);
	
	//APPEVENT_DATACACHE_SET_DATACACHE
	//SendAppEvent(AppEvent_StatusType::APPEVENT_PHONECALLBACK_SETSHOPPINGCARTINFO,AppEvent_ErrorCode::APPEVENT_ERRORCODE_OK,&s_pEcb);
};